<?php

namespace App\Http\Controllers;

use App\Library\Requests\Upload\UploadImageRequest;
use App\Library\Requests\Upload\UploadRequest;
use App\Library\Requests\Upload\UploadVideoRequest;
use App\Library\Service\UploadService;
use Encore\Admin\Controllers\AdminController;
use Illuminate\Http\JsonResponse;
use OSS\Core\OssException;
use OSS\Http\RequestCore_Exception;

class UploadController extends AdminController
{
    private UploadService $service;

    /**
     * @param UploadService $service
     */
    public function __construct(UploadService $service)
    {
        $this->service = $service;
    }

    /**
     * 上传文件
     * @param UploadRequest $request
     * @return JsonResponse
     * @throws OssException
     * @throws RequestCore_Exception
     */
    public function upload(UploadRequest $request): JsonResponse
    {
        return $this->service->index($request);
    }

    /**
     * image
     * @param UploadImageRequest $request
     * @return JsonResponse
     * @throws OssException
     * @throws RequestCore_Exception
     */
    public function image(UploadImageRequest $request): JsonResponse
    {
        return $this->service->image($request);
    }

    /**
     * video
     * @param UploadVideoRequest $request
     * @return JsonResponse
     * @throws OssException
     * @throws RequestCore_Exception
     */
    public function video(UploadVideoRequest $request): JsonResponse
    {
        return $this->service->video($request);
    }

    /**
     * 上传多文件
     * @return JsonResponse
     * @throws OssException|RequestCore_Exception
     */
    public function multiple():JsonResponse
    {
        return $this->service->multiple();
    }
}
